import { reqSearchInfo } from "../api/index.js"

// let res = reqSearchInfo({})
// console.log(res);

const search = {
    namespaced: true,  // 开启命名空间
    state:{
        searchInfo: {}  // 注意这里存放的是对象 不是数组
    },
    mutations:{
        RECEIVE_SEARCHINFO(state,searchInfo){
            state.searchInfo = searchInfo
        }
    },
    actions:{
        // async和await异步请求  这里记得带参数 searchParams
        async getSearchInfo({commit},searchParams){
            const result = await reqSearchInfo(searchParams)
            if(result.code === 200){
                commit('RECEIVE_SEARCHINFO',result.data)
            }
        }
    },
    getters:{
        // 简化数据 相当计算属性
        attrsList(state){
            return state.searchInfo.attrsList || []  // 没有数据则返回空数组
        },
        goodsList(state){
            return state.searchInfo.goodsList || []
        },
        trademarkList(state){
            return state.searchInfo.trademarkList || []
        }
    },
}

export default search